﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Models;
using BLL;

namespace CSMF
{
    public partial class two : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindVideo1();
                BindVideo2();
                BindVideo3();
                BindVideo4();
                BindVideo5();
                BindVideo6();
                BindVideo7();
            }
        }

        protected string GetStyle(object vid, object id, int index)
        {
            string style = "";
            if (vid == null)
            {
                if (index == 0)
                {
                    style = "currentBtn";
                }
            }
            else
            {
                if (Convert.ToInt32(vid) == Convert.ToInt32(id))
                {
                    style = "currentBtn";
                }
            }
            return style;
        }

        protected void BindVideo1()
        {
            IList<Models.VideoInfo> video = VideoInfoManager.GetVideoInfosByTypeID("1");
            this.AspNetPager1.RecordCount = video.Count;
            this.AspNetPager1.PageSize = 18;
            PagedDataSource pds = new PagedDataSource();
            pds.DataSource = video;
            pds.AllowPaging = true;
            pds.PageSize = 18;
            pds.CurrentPageIndex = this.AspNetPager1.CurrentPageIndex - 1;
            Repeater1.DataSource = pds;
            Repeater1.DataBind();
        }

        protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
        {
            this.AspNetPager1.CurrentPageIndex = e.NewPageIndex;
            BindVideo1();
        }

        protected void BindVideo2()
        {
            IList<Models.VideoInfo> video = VideoInfoManager.GetVideoInfosByTypeID("2");
            this.AspNetPager2.RecordCount = video.Count;
            this.AspNetPager2.PageSize = 18;
            PagedDataSource pds = new PagedDataSource();
            pds.DataSource = video;
            pds.AllowPaging = true;
            pds.PageSize = 18;
            pds.CurrentPageIndex = this.AspNetPager2.CurrentPageIndex - 1;
            Repeater2.DataSource = pds;
            Repeater2.DataBind();
        }

        protected void AspNetPager2_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
        {
            this.AspNetPager2.CurrentPageIndex = e.NewPageIndex;
            BindVideo2();
        }

        protected void BindVideo3()
        {
            IList<Models.VideoInfo> video = VideoInfoManager.GetVideoInfosByTypeID("3");
            this.AspNetPager3.RecordCount = video.Count;
            this.AspNetPager3.PageSize = 18;
            PagedDataSource pds = new PagedDataSource();
            pds.DataSource = video;
            pds.AllowPaging = true;
            pds.PageSize = 18;
            pds.CurrentPageIndex = this.AspNetPager3.CurrentPageIndex - 1;
            Repeater3.DataSource = pds;
            Repeater3.DataBind();
        }

        protected void AspNetPager3_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
        {
            this.AspNetPager3.CurrentPageIndex = e.NewPageIndex;
            BindVideo3();
        }

        protected void BindVideo4()
        {
            IList<Models.VideoInfo> video = VideoInfoManager.GetVideoInfosByTypeID("4");
            this.AspNetPager4.RecordCount = video.Count;
            this.AspNetPager4.PageSize = 18;
            PagedDataSource pds = new PagedDataSource();
            pds.DataSource = video;
            pds.AllowPaging = true;
            pds.PageSize = 18;
            pds.CurrentPageIndex = this.AspNetPager4.CurrentPageIndex - 1;
            Repeater4.DataSource = pds;
            Repeater4.DataBind();
        }

        protected void AspNetPager4_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
        {
            this.AspNetPager4.CurrentPageIndex = e.NewPageIndex;
            BindVideo4();
        }

        protected void BindVideo5()
        {
            IList<Models.VideoInfo> video = VideoInfoManager.GetVideoInfosByTypeID("5");
            this.AspNetPager5.RecordCount = video.Count;
            this.AspNetPager5.PageSize = 18;
            PagedDataSource pds = new PagedDataSource();
            pds.DataSource = video;
            pds.AllowPaging = true;
            pds.PageSize = 18;
            pds.CurrentPageIndex = this.AspNetPager5.CurrentPageIndex - 1;
            Repeater5.DataSource = pds;
            Repeater5.DataBind();
        }

        protected void AspNetPager5_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
        {
            this.AspNetPager5.CurrentPageIndex = e.NewPageIndex;
            BindVideo5();
        }

        protected void BindVideo6()
        {
            IList<Models.VideoInfo> video = VideoInfoManager.GetVideoInfosByTypeID("6");
            this.AspNetPager6.RecordCount = video.Count;
            this.AspNetPager6.PageSize = 18;
            PagedDataSource pds = new PagedDataSource();
            pds.DataSource = video;
            pds.AllowPaging = true;
            pds.PageSize = 18;
            pds.CurrentPageIndex = this.AspNetPager6.CurrentPageIndex - 1;
            Repeater6.DataSource = pds;
            Repeater6.DataBind();
        }

        protected void AspNetPager6_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
        {
            this.AspNetPager6.CurrentPageIndex = e.NewPageIndex;
            BindVideo6();
        }

        protected void BindVideo7()
        {
            IList<Models.VideoInfo> video = VideoInfoManager.GetVideoInfosByTypeID("7");
            this.AspNetPager7.RecordCount = video.Count;
            this.AspNetPager7.PageSize = 18;
            PagedDataSource pds = new PagedDataSource();
            pds.DataSource = video;
            pds.AllowPaging = true;
            pds.PageSize = 18;
            pds.CurrentPageIndex = this.AspNetPager7.CurrentPageIndex - 1;
            Repeater7.DataSource = pds;
            Repeater7.DataBind();
        }

        protected void AspNetPager7_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
        {
            this.AspNetPager7.CurrentPageIndex = e.NewPageIndex;
            BindVideo7();
        }

        protected string GetPoint(int id)
        {
            string point = "";
            Models.VideoInfo info = VideoInfoManager.GetVideoInfoByID(id);
            if (info.Point == 0)
            {
                point = Convert.ToSingle((VideoPointManager.GetVideoPointsSumByVideoID(id) / VideoPointManager.GetVideoPointsCountByVideoID(id))).ToString();
                if (point.Equals("非数字"))
                {
                    point = "0";
                }
            }
            else
            {
                point = info.Point.ToString();
            }
            return point;
        }

        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            Session["SearchTitle"] = txtSearch.Text.Trim();
            Response.Redirect("SearchMerak.aspx");
        }
    }
}